package flc.ast.adapter;


import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class LibraryChildAdapter extends StkProviderMultiAdapter<String> {
    public LibraryChildAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new LibraryChildProvider());
    }

    private class LibraryChildProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_library_child;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String bean) {
            Glide.with(getContext()).load(bean)
                    .into((ImageView) baseViewHolder.getView(R.id.ivLibraryChildItemImg));
            baseViewHolder.setText(R.id.tvLibraryChildItemName, FileUtils.getFileName(bean));
            baseViewHolder.setText(R.id.tvLibraryChildItemSize, ConvertUtils.byte2FitMemorySize(FileUtils.getLength(bean), 1));
            baseViewHolder.setText(R.id.tvLibraryChildItemDuration, TimeUtil.getHHmmss(MediaUtil.getDuration(bean)));
        }
    }

}
